/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;
import Util.MySqlDataAccessHelper;
import Pojo.TheLoai;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author USER
 */
public class TheLoaiDAO {
    //lấy thể loại theo mã
    
    public static TheLoai layThongTinTheLoai(int maTheLoai){
        TheLoai tl = new TheLoai();
        
        try{
            String sql = String.format("SELECT * FROM the_loai WHERE ma_the_loai=%d", maTheLoai);
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while(rs.next()){
                tl.setMaTheLoai(rs.getInt("ma_the_loai"));
                tl.setTenTheLoai(rs.getString("ten_the_loai"));
                tl.setMaDanhMucChiTiet(rs.getInt("ma_danh_muc"));
            }
            
            helper.close();
        }catch(Exception e){
            
        }
        
        return tl;
    }
    
    
    //lấy danh sách thể loại
    public static List<TheLoai> layDanhSachTheLoai(){
        List<TheLoai> tls = new ArrayList<TheLoai>();
        
        try{
            String sql = "SELECT * FROM the_loai";
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.open();
            ResultSet rs = helper.executeQuery(sql);
            while(rs.next()){
                TheLoai tl = new TheLoai();
                tl.setMaTheLoai(rs.getInt("ma_the_loai"));
                tl.setTenTheLoai(rs.getString("ten_the_loai"));
                tl.setMaDanhMucChiTiet(rs.getInt("ma_danh_muc"));
                tls.add(tl);
            }
            
            helper.close();
        }catch(Exception e){
            
        }
        
        return tls;
    }
}
